// https://leetcode-cn.com/problems/wiggle-subsequence/
// 376. 摆动序列

class Solution {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length <= 1) return nums.length;
        
        int pre_diff = 0;
        int cur_diff = 0;
        int result = 1;

        for (int i = 0; i < nums.length - 1; i++) {
            cur_diff = nums[i + 1] - nums[i];
            if ((pre_diff <= 0 && cur_diff > 0) || (pre_diff >= 0 && cur_diff < 0)) {
                result++;
                pre_diff = cur_diff;
            }
        }
        return result;
    }
}